<template>
  <div v-if="props.node">
    <!-- 路由节点 -->
    <RouterNode :node="props.node" @removeNode="removeNode" v-if="props.node.nodeType === ROUTER" />
    <!-- 普通节点 -->
    <BaseNode
      :node="props.node"
      :condition-nodes="props.branchNodes"
      :condition-index="props.conditionIndex"
      @removeNode="removeNode"
      v-else
    />
    <!-- 子节点 -->
    <NodeWrap
      :node="props.node.nextNode"
      @removeNode="removeChildNode"
      v-if="props.node.nextNode && props.node.nextNode.nodeType"
    />
  </div>
</template>

<script setup name="NodeWrap">
import BaseNode from "./BaseNode.vue";
import RouterNode from "./Node/RouterNode.vue";
import { ROUTER } from "./flow";

const props = defineProps({
  node: {
    // 当前流程节点数据
    type: Object,
    default: () => {}
  },
  branchNodes: {
    // 条件集合，当节点类型为condition时有效
    type: Array,
    default: () => []
  },
  conditionIndex: {
    // 当前条件节点的顺序，当节点类型为condition时有效
    type: Number,
    default: 0
  },
  canRemoved: {
    // 当前节点是否可以移除
    type: Boolean,
    default: true
  }
});

// 移除当前节点
const emit = defineEmits(["removeNode"]);
const removeNode = () => {
  emit("removeNode");
};

// 移除子节点
const removeChildNode = () => {
  let nextChildNode = props.node.nextNode.nextNode;
  props.node.nextNode = nextChildNode;
};
</script>

<style lang="scss" scoped></style>
